package com.tcs.test.docx4j.sign;

import com.tcs.model.standardization.SignTopicBean;
import com.tcs.model.teacherrubric.TopicTypeDistBean;
import com.tcs.server.teacherrubric.ITeacherRubricService;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 标识工厂
 */
@Component(value="signReturnFactory")
@Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON)
public class SignReturnFactory implements ISignReturnFactory {

    private SignTopicBean signTopicBean = new SignTopicBean();

    private List<TopicTypeDistBean> topicTypeDistBeanList;

    @Resource(name = "teacherRubricService")
    private ITeacherRubricService iTeacherRubricService;

    @Override
    public SignTopicBean getSignTopicBean(String line) {
        for (TopicTypeDistBean topicTypeDistBean : createDistBean()) {
            if (line.contains(topicTypeDistBean.getName())) {      // 如果是选择题 就为true
                if (topicTypeDistBean.getId().equals("1")) {
                    signTopicBean.setSign(Boolean.TRUE);
                    signTopicBean.setFlag(false);
                    return signTopicBean;
                } else {
                    signTopicBean.setSign(false);
                    signTopicBean.setFlag(true);
                    return signTopicBean;
                }
            } else {
                signTopicBean.setFlag(false);
            }
        }
        return signTopicBean;
    }

    private List<TopicTypeDistBean> createDistBean() {
        if (null == topicTypeDistBeanList) {
            topicTypeDistBeanList = iTeacherRubricService.querytopicTypeDistAll();
        }
        return topicTypeDistBeanList;
    }

    @Override
    public SignTopicBean getSignTopicBeanOnstatic() {
        return signTopicBean;
    }
}
